package org.chen.mapper.news;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.chen.model.CommentRule;
import org.chen.model.CommentTask;

import java.util.List;

@Mapper
public interface CommentRuleMapper extends BaseMapper<CommentRule> {
    @Insert("<script>" +
            "INSERT INTO comment_rule (" +
            "id, url_pattern, form_selector, action_url, comment_field, author_field, " +
            "email_field, url_field, hidden_field_names, use_count, success_rate, " +
            "last_used_time, create_time, update_time) VALUES " +
            "<foreach collection='rules' item='rule' separator=','>" +
            "(" +
            "#{rule.id}, " +
            "#{rule.urlPattern}, " +
            "#{rule.formSelector}, " +
            "#{rule.actionUrl}, " +
            "#{rule.commentField}, " +
            "#{rule.authorField}, " +
            "#{rule.emailField}, " +
            "#{rule.urlField}, " +
            "#{rule.hiddenFieldNames}, " +
            "#{rule.useCount}, " +
            "#{rule.successRate}, " +
            "#{rule.lastUsedTime}, " +
            "#{rule.createTime}, " +
            "#{rule.updateTime}" +
            ")" +
            "</foreach>" +
            "</script>")
    int batchInsert(@Param("rules") List<CommentRule> rules);

    /**
     * 通过批次号和目标URL查询
     */
    @Select("SELECT * FROM comment_rule " +
            "WHERE url_pattern = #{urlPattern} " +
            "LIMIT 1")
    CommentRule selectByUrl(@Param("urlPattern") String urlPattern);
}
